<?php
	/* Description: This file is used to add sub sub category. */
	#########IncludeFiles####################################################################################
	include_once '../inc/config.php';
	include_once("../inc/bootstrape.php");
	require_once _SITE_PATH_.'classes/Vendor/Vendor.php';
	require_once _SITE_PATH_.'classes/Category/Category.php';
	require_once _SITE_PATH_.'classes/Master/Master.php';
	require_once _SITE_PATH_.'classes/CommonUtility/CommonUtility.php';

	if( $_POST['submit']=='Submit'){    
		$parms['name'] 				= $_POST['name'];
		$parms['category']			= $_POST['category'];
		$parms['subcategory'] 		= $_POST['subcategory'];
		$parms['subsubcategory']	= $_POST['subsubcategory'];
		$parms['description'] 		= $_POST['description'];
		if(!empty($_POST['attributes'])){
			$parms['attributes'] 		= implode(',',$_POST['attributes']);
		}
		$parms['tags'] 				= $_POST['tags'];
		$parms['added']				= date("Y-m-d h:i:s");
						
		if( $servid=CommonUtility::insertData($parms, 'services_master', true)) {        
			//  add service attributes
			//below lines are comment for removing attributes from master service
//             $parms = array();
//             $parms['added'] = date('Y-m-d');
//             $parms['service_id'] = $servid;
// 			if(!empty($_POST['attributes'])){				
//                 $parms_attributes['service_id'] = $servid;
//                 foreach($_POST['attributes'] as $key => $val){
//                     $parms_attributes['attribute_id'] = $key;
//                     $parms_attributes['unit_id'] = $_POST['unit_'.$key];
//                     $unitRow = CommonUtility::getDataById($parms_attributes['unit_id'], 'unit_master');
//                     $parms_attributes['unit'] = $unitRow['title'] ;                                        
//                     foreach($val as $inner_key => $inner_val){
//                         $parms_attributes['attribute_name'] = $inner_key;
//                         $parms_attributes['attribute_value'] = $inner_val;
//                     }
//                     CommonUtility::insertData($parms_attributes, 'services_attributes');
//                 }
//             }
            
            header("Location: service_mng.php?msg=1614");            
			exit;
		}
		$err = 1615;    
	}

	$editor = CommonUtility::includeEditor();

	$main_categories = array();
	$main_categories = Category::getMainCategories();
	
    $sub_sub_categories = array();
    $sub_sub_categories = Category::getSubSubCategories();
    
	$drop_down_attributes = '';
	$drop_down_attributes = CommonUtility::getServiceAttributes();

	$errMsg = $err;
	$_tplName = 'master/service_add.tpl';
	$_title = 'Add Service';

	require_once _ADMIN_TPL_MAIN_;
?>